IF EXISTS ( SELECT  *
            FROM    dbo.sysobjects
            WHERE   id = OBJECT_ID(N'[CGO_EventCharityAdd]')
                    AND OBJECTPROPERTY(id, N'IsProcedure') = 1 ) 
  DROP PROCEDURE CGO_EventCharityAdd
GO

SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.CGO_EventCharityAdd
  @PortalID INT,
  @EventID INT ,
  @CharityID INT
AS 
  IF EXISTS ( SELECT  1
              FROM    dbo.CGO_Event
              WHERE   EventID = @EventID
                      AND PortalID = @PortalID )
    AND EXISTS ( SELECT 1
                 FROM   dbo.CGO_Charity
                 WHERE  CharityID = @CharityID
                        AND PortalID = @PortalID ) 
    BEGIN
      INSERT INTO dbo.CGO_EventCharity
              ( PortalID, EventID, CharityID )
      VALUES  ( @PortalID, -- PortalID - int
                @EventID, -- EventID - int
                @CharityID  -- CharityID - int
                )      
    END
GO
